﻿using T4UtilityBelt.Writers;

namespace T4UtilityBelt.UxDesigns.Controls.Renderers.Windows
{
    public class StackPanelRenderer : ControlRenderer<StackPanelControl, IStackPanelRenderer>, IStackPanelRenderer
    {
        protected override void OnRenderUiXmlBegin(StackPanelControl control, CodeWriter writer)
        {
            writer.WriteBeginTag("tcl:StackPanel");
            RenderControlAttributes(control, writer);
            if (control.Orientation == Orientation.Horizontal)
            {
                writer.WriteAttribute("Orientation", "Horizontal");
            }
            writer.AddBinding("TapCommand", control.Tap);
            writer.AddBinding("TapCommand", control.TapParameter);

            writer.WriteEnd();

            if (control.DataContext != null)
            {
                writer.WriteBeginTag("tcl:StackPanel");
                writer.AddBinding("DataContext", control.DataContext);
                writer.WriteEnd();
            }
        }

        protected override void OnRenderUiXmlContent(StackPanelControl control, CodeWriter writer)
        {
            control.Controls.RenderUiXml(writer);
        }

        protected override void OnRenderUiXmlEnd(StackPanelControl control, CodeWriter writer)
        {
            if (control.DataContext != null)
            {
                writer.WriteEndTag("tcl:StackPanel");
            }
            writer.WriteEndTag("tcl:StackPanel");
        }
    }
}
